package edu.ustb.service;

import java.io.InputStream;
import java.util.Random;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import edu.ustb.domain.User;
import edu.ustb.mapper.UserXiumiMapper;
import edu.ustb.utils.MybatisUtil;

public class UserEmailXiumiServiceImp implements UserEmailXiumiService {

	@Override
	public User findByEmail(String userEmail) {
		UserXiumiMapper mapper=MybatisUtil.getMapper(UserXiumiMapper.class);
		User user=mapper.findByEmail(userEmail);
		return user;
	}

	@Override
	public String creatYzm() {
		int length=5;
		String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	     Random random=new Random();
	     StringBuffer sb=new StringBuffer();
	     for(int i=0;i<length;i++){
	       int number=random.nextInt(62);
	       sb.append(str.charAt(number));
	     }
	     return sb.toString();
		
		
	}

	@Override
	public int addYzmByEmail(String userYzm, String userEmail) {
		UserXiumiMapper mapper=MybatisUtil.getMapper(UserXiumiMapper.class);
		int row = mapper.addYzmByEmail(userYzm,userEmail);
		MybatisUtil.commit();
		return row;
	}

	@Override
	public User findByPhone(String userPhone) {
		UserXiumiMapper mapper=MybatisUtil.getMapper(UserXiumiMapper.class);
		User user=mapper.findByPhone(userPhone);
		return user;
	}

	

}
